from tree_sitter_language_pack import get_parser


def parse_code(language, code):
    # 获取指定语言的解析器
    parser = get_parser(language)

    # 解析代码
    tree = parser.parse(bytes(code, "utf8"))

    # 返回语法树的根节点
    return tree.root_node


# 解析JavaScript代码
js_code = "function add(a, b) { return a + b; }"
js_tree = parse_code('javascript', js_code)
print(js_tree)

